#include "Decoder.hpp"

void Decoder::setDesiredFrequency(unsigned int df) {desiredFrequency=df;}
unsigned short Decoder::getChannelCount() {return channels;}
unsigned int Decoder::getFrequency() {return frequency;}
unsigned int Decoder::getSampleRate() {return frequency;}
uint64_t Decoder::getSampleCount() {return samples;}
const char* Decoder::getErrorMessage() {return errorMessage.c_str();}

unsigned int Decoder::getFrameToDecode(unsigned int outFrames) {
    if(desiredFrequency==frequency) return outFrames;
    float ratio=desiredFrequency/frequency;
    return ceil(outFrames/ratio);
}

void Decoder::resample(SRC_DATA *data) {
    if(sState==NULL) sState=src_new(SRC_SINC_BEST_QUALITY , channels, NULL);
    src_process(sState, data); //==0 -> OK
}

Decoder::Decoder() : sState(NULL) {}

Decoder::~Decoder() {
    if(sState!=NULL) sState=src_delete(sState);
}
